package createThread.cn.tedu.threaddemo.test7;

import java.util.Scanner;

public class Demo1 {
    public static volatile boolean isRunning = true;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            while(isRunning){
                //空
            }
            System.out.println("线程1结束");
        });
        Thread t2 = new Thread(()->{
            System.out.println("请输入一个非零的数字来打断线程2");
            Scanner scan = new Scanner(System.in);
            if(scan.nextInt() != 0){
                isRunning = false;
            }
            System.out.println("线程2结束");
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();

    }
}
